package com.ylesb.ioc;
/**
 * @title: OkHttpMain
 * @projectName springdemo
 * @description: TODO
 * @author White
 * @site : [www.ylesb.com]
 * @date 2022/7/616:26
 */

import okhttp3.*;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @className    : OkHttpMain
 * @description  : [描述说明该类的功能]  
 * @author       : [XuGuangchao]
 * @site         : [www.ylesb.com]
 * @version      : [v1.0]
 * @createTime   : [2022/7/6 16:26]
 * @updateUser   : [XuGuangchao]
 * @updateTime   : [2022/7/6 16:26]
 * @updateRemark : [描述说明本次修改内容] 
 */

public class OkHttpMain {
    public static void main(String[] args) {
        //OkHttpClient okHttpClient = new OkHttpClient.Builder()
        //        .build();
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        OkHttpClient okHttpClient = ctx.getBean("okHttpClient", OkHttpClient.class);
        Request request = new Request.Builder()
                .get()
                .url("http://www.baidu.com")
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                System.out.println("e.getMessage() = " + e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                System.out.println("response.body() = " + response.body().string());
            }
        });
    }
}

